<?php 
    session_start();

    if (!isset($_SESSION['is_logged_in'])) {
        header("Location:index.php?url=" . $_SERVER["REQUEST_URI"]);
        die();
    }
    else
    	include("php/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
	<head>
		<meta name="description" content="Torneo Comercial de Basket">
		<meta name="keywords" content="torneo.basket,comercial,amateur,vector,it,vector-it,cordoba,argentina">
		<meta name="author" content="Vector-IT">
	    <title>Torneo TCB</title>
	    <link rel="shortcut icon" href="imagenes/favicon.ico" type="image/x-icon" />
	    <link rel="icon" href="imagenes/favicon.ico" type="image/x-icon" />
		<link rel="image_src" href="http://www.torneotcb.com.ar/imagenes/logo.png" />
		<link rel="stylesheet" type="text/css" href="css/tcb.css">
	    
        <meta property="og:title" content="Torneo TCB" />
		<meta property="og:url" content="http://www.torneotcb.com.ar" />
		<meta property="og:description" content="Torneo Comercial de Basket" />
		<meta property="og:image" content="http://www.torneotcb.com.ar/imagenes/logo.png" />
		
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="jquery/css/custom-theme/jquery-ui-1.10.3.custom.min.css" />
		<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
		<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
		<!--
		<script src="jquery/js/jquery-1.9.1.js"></script>
		<script src="jquery/js/jquery-ui-1.10.3.custom.js"></script>
		--> 
		
		<script src="js/publicos.js"></script>	
	    
		<!-- Google Hosted jQuery Core -->
		<!-- 
		<script src="http://www.google.com/jsapi"></script>
		<script>google.load("jquery", "1");</script> -->
		<script src="js/jquery.ez-bg-resize.js" type="text/javascript" charset="utf-8"></script>
		<script>
			$(document).ready(function() {
				
				var BGImageArray = ["bg.jpg","bg2.jpg","bg5.jpg","bg6.jpg","bg7.jpg","bg8.jpg"];
				var BGImage = BGImageArray[Math.floor(Math.random()*BGImageArray.length)];
	
				$("body").ezBgResize({
					img     : "imagenes/fondos/" + BGImage, // Relative path example.  You could also use an absolute url (http://...).
					opacity : 1, // Opacity. 1 = 100%.  This is optional.
					center  : true // Boolean (true or false). This is optional. Default is true.
				});
			});
		</script>
		<script type="text/javascript">
			function armarPagina() {
				cargarEncabezado(function(){return true;});
			}
	
			function cargarEncabezado(callback) {
	            if (window.XMLHttpRequest)
	            {// code for IE7+, Firefox, Chrome, Opera, Safari
	                xmlhttp=new XMLHttpRequest();
	            }
	            else
	            {// code for IE6, IE5
	                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	            }
	
	            xmlhttp.onreadystatechange=function()
	            {
	                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
	                	document.getElementById("divEncabezado").innerHTML = xmlhttp.responseText;
	                	callback();
	                }
	            };
	            xmlhttp.open("POST","encabezado.php",true);
	            xmlhttp.send();
			}
			
			function online(NumePart) {
				//var NumePart = verNumePart();

				if (NumePart != "")
					location.href = "partidoON.php?NumePart="+NumePart;
			}

			function offline() {
				var NumePart = verNumePart();

				if (NumePart != "")
					location.href = "partidoOFF.php?NumePart="+NumePart;
			}

			function verNumePart() {
				var I, cantPart, NumePart = "";

				cantPart = document.getElementById('hdnCantPart').value;

				for (I = 1; I <= cantPart; I++) 
					if (document.getElementById('opt'+I).checked) {
						NumePart = document.getElementById('opt'+I).value;
						break;
					}
				return NumePart;
			}
		</script>
	</head>
	<body onload="armarPagina();">
		<?php include_once("php/analyticstracking.php");?>
	
		<div class="contenedor">
	    	<input type="hidden" id="hdnOperacion" name="hdnValor" value="" />
	        <input type="hidden" id="hdnNumePart" name="hdnValor" value="" />
	    	
		    <div class="encabezado" id="divEncabezado">
		    	<img src="imagenes/logo_viejo.png" />
			</div>
	        	    
	    	<div class="contenido">
				<div class="tituloBajo">Seleccione el partido</div>
				<?php
	    			$conn = new mysqli($dbhost, $dbuser, $dbpass, $db);
	    			
	    			$strSQL = "SELECT p.NumePart, p.NumeTorneo, t.NombTorneo, p.NumeFech, DATE_FORMAT(p.FechPart, '%d/%m/%y') FechPart, DATE_FORMAT(p.FechPart, '%H:%i') HoraPart, el.NombEqui NombEquiLoca, ev.NombEqui NombEquiVisi";
	    			$strSQL.= " FROM partidos p";
	    			$strSQL.= " INNER JOIN torneos t ON p.NumeTorneo = t.NumeTorneo";
	    			$strSQL.= " INNER JOIN equipos el ON p.NumeEquiLoca = el.NumeEqui";
	    			$strSQL.= " INNER JOIN equipos ev ON p.NumeEquiVisi = ev.NumeEqui";
	    			$strSQL.= " WHERE p.NumeEsta = 2";
	    			$strSQL.= " ORDER BY t.NombTorneo, p.FechPart";
	    			
	    			$tabla = $conn->query($strSQL) or die("Problemas al conectar al Servidor");
	    			
	    			if ($tabla->num_rows > 0) {
						$strSalida = '<input type="hidden" id="hdnCantPart" value="'.$tabla->num_rows.'" />';
						$strSalida.= $crlf.'<table class="tabla">';
						$strSalida.= $crlf.'<tr class="tablaFilaTitulo">';
						$strSalida.= $crlf.'<th></th>';
						$strSalida.= $crlf.'<th>Torneo</th>';
						$strSalida.= $crlf.'<th>Fecha</th>';
						$strSalida.= $crlf.'<th>Hora</th>';
						$strSalida.= $crlf.'<th>Equipo Local</th>';
						$strSalida.= $crlf.'<th>Equipo Visitante</th>';
						$strSalida.= $crlf.'</tr>';
						$I = 1;
						
						while ($fila = $tabla->fetch_array()) {
							if ($I % 2 == 0)
								$strSalida.= $crlf.'<tr class="tablaFilaAlternativa">';
							else
								$strSalida.= $crlf.'<tr class="tablaFilaNormal">';
							
	
							$strSalida.= $crlf.'<td><input type="button" class="boton" id="btnNumePart'.$fila["NumePart"].'" value="Seleccionar" onclick="online('.$fila["NumePart"].')" /></td>';
							$strSalida.= $crlf.'<td>'.$fila["NombTorneo"].'</td>';
							$strSalida.= $crlf.'<td>'.$fila["FechPart"].'</td>';
							$strSalida.= $crlf.'<td>'.$fila["HoraPart"].'</td>';
							$strSalida.= $crlf.'<td>'.$fila["NombEquiLoca"].'</td>';
							$strSalida.= $crlf.'<td>'.$fila["NombEquiVisi"].'</td>';
							$strSalida.= $crlf.'</tr>';
							$I++;
						}
						$strSalida.= $crlf."</table>";
					}
					else
						$strSalida = "No hay partidos a disputar.";
					
					echo $strSalida;
	    		?>
	    	</div>
	
		    <div id="pie" class="pie">
            	<div style="float: left;">
            		Estamos en Redes Sociales
            	  	<a href="http://www.facebook.com/pages/Torneo-Comercial-De-Basquet/126750014062523" target="_blank"><img src="imagenes/facelogo.png" height="25" width="25"  /></a>
            	  	<a href="http://twitter.com/TorneoComercial" target="_blank"><img src="imagenes/twitlogo.png" height="25" width="25" /></a>
            	</div>
                <div style="float: right;">
                	<p>
                		2013 Copyright Torneo TCB.<br/>
                		Todos los derechos reservados.<br/>
                    	Powered by <a href="http://www.vector-it.com.ar" target="_blank"><img src="imagenes/vectorit.png" height="15" width="15" />Vector-IT</a>
                    </p>
				</div>
		    </div>
	    		    
		</div>
	</body>
</html>